home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
PTR-TCL v2.1
/
3) inherited fixer
/
ClassOp.c
next >
Wrap
Text File
|
1994-01-15
|
3KB
|
138 lines
/*
* ClassOp.c
*/
#include <string.h>
#include <stdio.h>
#define isspace(x) (((x)==32)||((x)==9))
short ReadClasses ( unsigned char * name ) ;
extern void Message ( unsigned char * message ) ;
extern void Try ( short code ) ;
extern unsigned char * C2P ( char * ) ;
void LookupParent ( char * child , char * parent ) ;
typedef struct classMap {
char superClass [ 256 ] ;
char subClass [ 256 ] ;
} ClassMap ;
ClassMap * * root ;
static char *
P2C ( unsigned char * p ) {
int len = * p ;
if ( len ) {
BlockMove ( p + 1 , p , len ) ;
}
p [ len ] = 0 ;
return ( char * ) p ;
}
static void
Register ( unsigned char * cls , unsigned char * bas ) {
ClassMap map ;
strcpy ( map . superClass , P2C ( bas ) ) ;
strcpy ( map . subClass , P2C ( cls ) ) ;
PtrAndHand ( ( Ptr ) & map , ( Handle ) root , sizeof ( ClassMap ) ) ;
Try ( MemError ( ) ) ;
}
static short
ParseClasses ( Handle text ) {
long pos = 0 ;
Str255 cls ;
Str255 bas ;
long lk = 0 ;
long end = GetHandleSize ( text ) ;
int line = 1 ;
short errs = 0 ;
while ( pos < end ) {
cls [ 0 ] = 0 ;
bas [ 0 ] = 0 ;
lk = pos ;
while ( pos < end ) {
if ( ( * text ) [ pos ] == '\r' ) {
pos ++ ;
break ;
line ++ ;
}
pos ++ ;
}
while ( ! isspace ( ( * text ) [ lk ] ) && ( lk < pos ) ) {
cls [ ++ cls [ 0 ] ] = ( * text ) [ lk ++ ] ;
}
while ( isspace ( ( * text ) [ lk ] ) && ( lk < pos ) ) {
lk ++ ;
}
while ( ! isspace ( ( * text ) [ lk ] ) && ( lk < pos ) ) {
bas [ ++ bas [ 0 ] ] = ( * text ) [ lk ++ ] ;
}
if ( cls [ 0 ] && bas [ 0 ] ) {
Register ( cls , bas ) ;
} else {
sprintf ( ( char * ) bas , "\rLine %d: not a relation" , line ) ;
Message ( C2P ( ( char * ) bas ) ) ;
}
}
return errs ;
}
short
ReadClasses ( unsigned char * name ) {
short ref = 0 ;
Handle text ;
long size ;
short err ;
root = ( ClassMap * * ) NewHandle ( 0L ) ;
err = FSOpen ( name , 0 , & ref ) ;
if ( err || ! ref ) {
return err ? err : fnfErr ;
}
Try ( GetEOF ( ref , & size ) ) ;
text = NewHandle ( size ) ;
if ( ! text ) {
Try ( MemError ( ) ) ;
}
HLock ( text ) ;
Try ( FSRead ( ref , & size , * text ) ) ;
err = ParseClasses ( text ) ;
FSClose ( ref ) ;
DisposeHandle ( text ) ;
HLockHi ( ( Handle ) root ) ;
return err ;
}
void
LookupParent ( char * child , char * parent ) {
ClassMap * map ;
ClassMap * end ;
map = * root ;
end = * root + ( GetHandleSize ( ( Handle ) root ) / sizeof ( ClassMap ) ) ;
while ( map < end ) {
if ( ! strcmp ( map -> subClass , child ) ) {
strcpy ( parent , map -> superClass ) ;
return ;
}
map ++ ;
}
* parent = 0 ;
* child = 0 ;
}